home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / IEditor / Generators / C / code_misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-17  |  21.9 KB  |  672 lines

  1. /// Includes
  2. #define INTUI_V36_NAMES_ONLY
  3.  
  4. #include <exec/nodes.h>                 // exec
  5. #include <exec/lists.h>
  6. #include <exec/types.h>
  7. #include <dos/dos.h>                    // dos
  8. #include <dos/dostags.h>
  9. #include <intuition/intuition.h>        // intuition
  10. #include <clib/exec_protos.h>           // protos
  11. #include <clib/dos_protos.h>
  12. #include <pragmas/exec_pragmas.h>       // pragmas
  13. #include <pragmas/dos_pragmas.h>
  14.  
  15. #include <string.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <ctype.h>
  19.  
  20. #include "DEV_IE:Generators/defs.h"
  21. #include "DEV_IE:Include/IEditor.h"
  22. #include "DEV_IE:Generators/C/Protos.h"
  23. ///
  24.  
  25.  
  26. /// WriteMain
  27. void WriteMain( struct GenFiles *Files, struct IE_Data *IE )
  28. {
  29.     struct LibNode     *lib;
  30.     struct WndToOpen   *wto;
  31.     BOOL               bool;
  32.  
  33.     FPrintf( Files->Main,
  34.     "#define INTUI_V36_NAMES_ONLY\n\n"
  35.     "#include <dos/dos.h>\n"
  36.     "#include <exec/libraries.h>\n"
  37.     "#include <clib/exec_protos.h>\n"
  38.     "#include <clib/dos_protos.h>\n\n"
  39.     "#include <stdio.h>\n"
  40.     "#include <stdlib.h>\n"
  41.     "#include <string.h>\n"
  42.     "#include <errno.h>\n\n"
  43.     "#include \"%s\"\n"
  44.     "int    main( void );\n"
  45.     "void   OpenLibs( void );\n"
  46.     "void   Setup( void );\n"
  47.     "void   CloseLibs( void );\n"
  48.     "void   CloseAll( void );\n"
  49.     "void   PlayTheGame( void );\n"
  50.     "void   Error( STRPTR, STRPTR );\n"
  51.     "void   End( ULONG );\n",
  52.     FilePart( Files->XDefName ));
  53.  
  54.     if( IE->MainProcFlags & MAIN_WB )
  55.     FPuts( Files->Main, "int    wbmain( struct WBStartup * );\n" );
  56.  
  57.     if( IE->ExtraProc[0] ) {
  58.     FPrintf( Files->Main, "extern void %s( void );\n", IE->ExtraProc );
  59.  
  60.     if( Prefs.Flags & GEN_TEMPLATE ) {
  61.         FPrintf( Files->Temp,
  62.         "void %s( void )\n"
  63.         "{\n"
  64.         "\t/*  ...Initialization Stuff...  */\n"
  65.         "}\n",
  66.         IE->ExtraProc );
  67.     }
  68.     }
  69.  
  70.     if( IE->MainProcFlags & MAIN_OTHERBITS ) {
  71.     FPuts( Files->Main, "extern BOOL HandleOtherSignals( void );\n" );
  72.  
  73.     if( Prefs.Flags & GEN_TEMPLATE ) {
  74.         FPuts( Files->Temp,
  75.         "BOOL HandleOtherSignals( void )\n"
  76.         "{\n"
  77.         "\t/*  Routine to handle other signals  */\n"
  78.         "\treturn( TRUE );\n"
  79.         "}\n" );
  80.     }
  81.     }
  82.  
  83.     FPuts( Files->Main,
  84.     "\nBOOL\t\t\tOk_to_Run = TRUE;\n"
  85.     "ULONG\t\t\tmask = NULL;\n\n"
  86.     "extern struct Library\t*SysBase;\n"
  87.     "extern struct Library\t*DOSBase;\n" );
  88.  
  89.     if( IE->MainProcFlags & MAIN_WB )
  90.     FPuts( Files->Main, "struct WBStartup\t\t*WBMsg = NULL;\n" );
  91.  
  92.     for( lib = IE->Libs_List.mlh_Head; lib->lbn_Node.ln_Succ; lib = lib->lbn_Node.ln_Succ )
  93.     FPrintf( Files->Main, "struct Library\t\t*%s = NULL;\n", lib->lbn_Base );
  94.  
  95.  
  96.     FPuts( Files->Main,
  97.     "\n#include \"IE_Errors.h\"\n"
  98.     "\nint main( void )\n"
  99.     "{\n"
  100.     "\tOpenLibs();\n"
  101.     "\tSetup();\n" );
  102.  
  103.     if( IE->ExtraProc[0] )
  104.     FPrintf( Files->Main, "\t%s();\n", IE->ExtraProc );
  105.  
  106.     FPuts( Files->Main,
  107.     "\tPlayTheGame();\n"
  108.     "\tEnd( RETURN_OK );\n"
  109.     "}\n\n"
  110.     "void End( ULONG RetCode )\n"
  111.     "{\n"
  112.     "\tCloseAll();\n"
  113.     "\tCloseLibs();\n"
  114.     "\texit( RetCode );\n"
  115.     "}\n\n"
  116.     "void OpenLibs( void )\n"
  117.     "{\n" );
  118.  
  119.     for( lib = IE->Libs_List.mlh_Head; lib->lbn_Node.ln_Succ; lib = lib->lbn_Node.ln_Succ ) {
  120.     if ( lib->lbn_Node.ln_Pri & L_FAIL )
  121.         FPrintf( Files->Main,
  122.              "\tif (!( %s = OpenLibrary( \"%s\", %ld )))\n"
  123.              "\t\tError( ErrStrings[ OPEN_LIB ], \"%s\" );\n",
  124.              lib->lbn_Base, lib->lbn_Name, lib->lbn_Version, lib->lbn_Name );
  125.     else
  126.         FPrintf( Files->Main,
  127.              "\t%s = OpenLibrary( \"%s\", %ld );\n",
  128.              lib->lbn_Base, lib->lbn_Name, lib->lbn_Version );
  129.     }
  130.  
  131.     FPuts( Files->Main,
  132.        "}\n\n"
  133.        "void Setup( void )\n"
  134.        "{\n"
  135.        "\tULONG\t\tret;\n" );
  136.  
  137.     if( IE->SrcFlags & OPENDISKFONT ) {
  138.     struct TxtAttrNode *fnt;
  139.  
  140.     bool = FALSE;
  141.     for( fnt = IE->FntLst.mlh_Head; fnt->txa_Next; fnt = fnt->txa_Next )
  142.         if( fnt->txa_Flags & FPB_DISKFONT )
  143.         bool = TRUE;
  144.  
  145.     if( bool )
  146.         FPuts( Files->Main,
  147.            "\tif (!( OpenDiskFonts()))\n"
  148.            "\t\tError( ErrStrings[ OPEN_FONTS ], NULL );\n" );
  149.     }
  150.  
  151.     if( IE->SrcFlags & LOCALIZE )
  152.     FPuts( Files->Main, "\tSetupLocale();\n" );
  153.  
  154.     FPuts( Files->Main,
  155.        "\tif ( ret = SetupScreen())\n"
  156.        "\t\tError( ErrStrings[ SETUP_SCR ], ErrStrings[ SETUP_SCR+ret ]);\n" );
  157.  
  158.     for( wto = IE->WndTO_List.mlh_Head; wto->wto_Node.ln_Succ; wto = wto->wto_Node.ln_Succ )
  159.     FPrintf( Files->Main,
  160.          "\tif ( ret = Open%sWindow())\n"
  161.          "\t\tError( ErrStrings[ OPEN_WND ], ErrStrings[ OPEN_WND+ret ]);\n",
  162.          wto->wto_Label );
  163.  
  164.     if( IE->NumRexxs )
  165.     FPuts( Files->Main, "\tSetupRexxPort();\n" );
  166.  
  167.     FPuts( Files->Main,
  168.        "}\n\n"
  169.        "void CloseAll( void )\n"
  170.        "{\n" );
  171.  
  172.     for( wto = IE->WndTO_List.mlh_Head; wto->wto_Node.ln_Succ; wto = wto->wto_Node.ln_Succ )
  173.     FPrintf( Files->Main, "\tClose%sWindow();\n", wto->wto_Label );
  174.  
  175.     FPuts( Files->Main, "\tCloseDownScreen();\n" );
  176.  
  177.     if(( IE->SrcFlags & OPENDISKFONT ) && ( bool ))
  178.     FPuts( Files->Main, "\tCloseDiskFonts();\n" );
  179.  
  180.     if( IE->NumRexxs )
  181.     FPuts( Files->Main, "\tDeleteRexxPort();\n" );
  182.  
  183.     FPuts( Files->Main, "}\n\nvoid CloseLibs( void )\n{\n" );
  184.  
  185.     for( lib = IE->Libs_List.mlh_Head; lib->lbn_Node.ln_Succ; lib = lib->lbn_Node.ln_Succ )
  186.     FPrintf( Files->Main, "\tif ( %s )\n"
  187.                   "\t\tCloseLibrary( %s );\n",
  188.          lib->lbn_Base, lib->lbn_Base );
  189.  
  190.     FPuts( Files->Main,
  191.        "}\n\n"
  192.        "void PlayTheGame( void )\n"
  193.        "{\n"
  194.        "\tULONG\tsignals" );
  195.  
  196.     if( IE->MainProcFlags & MAIN_OTHERBITS )
  197.     FPuts( Files->Main, ", other = mask" );
  198.  
  199.     FPuts( Files->Main, ";\n" );
  200.  
  201.     for( wto = IE->WndTO_List.mlh_Head; wto->wto_Node.ln_Succ; wto = wto->wto_Node.ln_Succ )
  202.     FPrintf( Files->Main, "\tULONG\t%s_signal = 1 << %sWnd->UserPort->mp_SigBit;\n",
  203.          wto->wto_Label, wto->wto_Label );
  204.  
  205.     if( IE->NumRexxs )
  206.     FPuts( Files->Main, "\tULONG\trexx_signal = NULL;\n\n"
  207.                 "\tif ( RexxPort )\n"
  208.                 "\t\trexx_signal = 1 << RexxPort->mp_SigBit;\n\n" );
  209.  
  210.     FPuts( Files->Main, "\tmask = mask" );
  211.  
  212.     if( IE->MainProcFlags & MAIN_CTRL_C )
  213.     FPuts( Files->Main, " | SIGBREAKF_CTRL_C" );
  214.  
  215.     for( wto = IE->WndTO_List.mlh_Head; wto->wto_Node.ln_Succ; wto = wto->wto_Node.ln_Succ )
  216.     FPrintf( Files->Main, " | %s_signal", wto->wto_Label );
  217.  
  218.     if( IE->NumRexxs )
  219.     FPuts( Files->Main, " | rexx_signal" );
  220.  
  221.     FPuts( Files->Main, ";\n\n\twhile( Ok_to_Run ) {\n\t\tsignals = Wait( mask );\n" );
  222.  
  223.     for( wto = IE->WndTO_List.mlh_Head; wto->wto_Node.ln_Succ; wto = wto->wto_Node.ln_Succ )
  224.     FPrintf( Files->Main, "\t\tif (signals & %s_signal)\n"
  225.                   "\t\t\tOk_to_Run = Handle%sIDCMP();\n",
  226.          wto->wto_Label, wto->wto_Label );
  227.  
  228.     if( IE->NumRexxs )
  229.     FPuts( Files->Main, "\t\tif (signals & rexx_signal)\n"
  230.                 "\t\t\tHandleRexxMsg();\n" );
  231.  
  232.     if( IE->MainProcFlags & MAIN_OTHERBITS )
  233.     FPuts( Files->Main, "\t\tif (signals & other)\n"
  234.                 "\t\t\tOk_to_Run = HandleOtherSignals();\n" );
  235.  
  236.     if( IE->MainProcFlags & MAIN_CTRL_C )
  237.     FPuts( Files->Main, "\t\tif (signals & SIGBREAKF_CTRL_C)\n"
  238.                 "\t\t\tOk_to_Run = FALSE;\n" );
  239.  
  240.     FPuts( Files->Main, "\t};\n\n}\n" );
  241.  
  242.     if( IE->MainProcFlags & MAIN_WB )
  243.     FPuts( Files->Main, "\nint wbmain( struct WBStartup *msg )\n{\n"
  244.                 "\tWBMsg = msg;\n"
  245.                 "\treturn( main() );\n}\n" );
  246. }
  247. ///
  248.  
  249. /// WriteSetupScr
  250. void WriteSetupScr( struct GenFiles *Files, struct IE_Data *IE )
  251. {
  252.     if( IE->SrcFlags & FONTSENSITIVE ) {
  253.  
  254.     FPuts( Files->XDef, "extern WORD ScaleX( WORD );\n"
  255.                 "extern WORD ScaleY( WORD );\n" );
  256.  
  257.     FPrintf( Files->Std, "\nWORD ScaleX( WORD value )\n"
  258.                  "{\n"
  259.                  "\treturn(( WORD )((( FontX * value ) + %ld ) / %ld ));\n"
  260.                  "}\n"
  261.                  "\n"
  262.                  "WORD ScaleY( WORD value )\n"
  263.                  "{\n"
  264.                  "\treturn(( WORD )((( FontY * value ) + %ld ) / %ld ));\n"
  265.                  "}\n"
  266.                  "\n"
  267.                  "static void ComputeFont( UWORD width, UWORD height )\n"
  268.                  "{\n"
  269.                  "\tFont = &Attr;\n"
  270.                  "\tFont->ta_Name = (STRPTR)Scr->RastPort.Font->tf_Message.mn_Node.ln_Name;\n"
  271.                  "\tFont->ta_YSize = FontY = Scr->RastPort.Font->tf_YSize;\n"
  272.                  "\tFontX = Scr->RastPort.Font->tf_XSize;\n"
  273.                  "\n"
  274.                  "\tXOffset = Scr->WBorLeft;\n"
  275.                  "\tYOffset = Scr->RastPort.TxHeight + Scr->WBorTop;\n"
  276.                  "\n"
  277.                  "\tif( width && height )\n"
  278.                  "\t\tif((( ScaleX( width ) + Scr->WBorRight ) > Scr->Width ) ||\n"
  279.                  "\t\t\t(( ScaleY( height ) + Scr->WBorBottom + YOffset ) > Scr->Height ))\n"
  280.                  "\t\t\t\t{\n"
  281.                  "\t\t\t\t\tFont->ta_Name = (STRPTR)\"topaz.font\";\n"
  282.                  "\t\t\t\t\tFontX = FontY = Font->ta_YSize = 8;\n"
  283.                  "\t\t\t\t}\n"
  284.                  "}\n",
  285.          IE->ScreenData->Screen->RastPort.Font->tf_XSize >> 1,
  286.          IE->ScreenData->Screen->RastPort.Font->tf_XSize,
  287.          IE->ScreenData->Screen->RastPort.Font->tf_YSize >> 1,
  288.          IE->ScreenData->Screen->RastPort.Font->tf_YSize );
  289.     }
  290.  
  291.     FPuts( Files->Std, "\nint SetupScreen( void )\n"
  292.                "{\n" );
  293.  
  294.     if( IE->flags_2 & GENERASCR ) {
  295.  
  296.     if( IE->ScreenData->Type == 0 )
  297.         FPrintf( Files->Std, "\tif( LockPubScreen( %s ))\n"
  298.                  "\t\treturn( 1L );\n\n",
  299.              IE->ScreenData->PubName );
  300.  
  301.     FPuts( Files->Std, "\tif(!( Scr = OpenScreenTagList( NULL, (struct TagItem *)ScreenTags" );
  302.     } else
  303.     FPuts( Files->Std, "\tif(!( Scr = LockPubScreen( PubScreenName" );
  304.  
  305.     FPuts( Files->Std, " )))\n\t\treturn( 1L );\n\n" );
  306.  
  307.     if( IE->ScreenData->Type == 0 )
  308.     FPuts( Files->Std, "\tPubScreenStatus( Scr, 0 );\n\n" );
  309.  
  310.     if( IE->SrcFlags & FONTSENSITIVE )
  311.     FPuts( Files->Std, "\tComputeFont( 0, 0 );\n" );
  312.     else
  313.     FPuts( Files->Std, "\tYOffset = Scr->WBorTop + Scr->Font->ta_YSize;\n"
  314.                "\tXOffset = Scr->WBorLeft;\n" );
  315.  
  316.     FPuts( Files->Std, "\n\tif(!( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))\n"
  317.                "\t\treturn( 2L );\n" );
  318.  
  319.     if(( IE->SrcFlags & SHARED_PORT ) && (!( IE->SharedPort[0] )))
  320.     FPuts( Files->Std, "\n\tif(!( IDCMPPort = CreateMsgPort() ))\n"
  321.                "\t\treturn( 3L );\n" );
  322.  
  323.     // Expanders
  324.     ( *IE->IEXSrcFun->Setup )( Files );
  325.  
  326.     FPuts( Files->Std, "\n"
  327.                "\treturn( 0L );\n"
  328.                "}\n\n"
  329.                "void CloseDownScreen( void )\n"
  330.                "{\n"
  331.                "\tif( VisualInfo ) {\n"
  332.                "\t\tFreeVisualInfo( VisualInfo );\n"
  333.                "\t\tVisualInfo = NULL;\n"
  334.                "\t}\n" );
  335.  
  336.     // Expanders
  337.     ( *IE->IEXSrcFun->CloseDown )( Files );
  338.  
  339.     FPuts( Files->Std, "\n\tif( Scr ) {\n\t\t" );
  340.  
  341.     if( IE->flags_2 & GENERASCR )
  342.     FPuts( Files->Std, "CloseScreen(" );
  343.     else
  344.     FPuts( Files->Std, "UnlockPubScreen( NULL," );
  345.  
  346.     FPuts( Files->Std, " Scr );\n"
  347.                "\t\tScr = NULL;\n"
  348.                "\t}\n" );
  349.  
  350.     if(( IE->SrcFlags & SHARED_PORT ) && (!( IE->SharedPort[0] )))
  351.     FPuts( Files->Std, "\tif( IDCMPPort ) {\n"
  352.                "\t\tDeleteMsgPort( IDCMPPort );\n"
  353.                "\t\tIDCMPPort = NULL;\n"
  354.                "\t}" );
  355.  
  356.     FPuts( Files->Std, "\n}\n"
  357.                "\n"
  358.                "LONG OpenWnd( struct Gadget *GList, struct TagItem WTags[], struct Window **Wnd )\n"
  359.                "{\n"
  360.                "\tUWORD\t\ttc;\n" );
  361.  
  362.     if( IE->SrcFlags & FONTSENSITIVE )
  363.     FPuts( Files->Std, "\tUWORD\t\tww, wh, oldww, oldwh;\n" );
  364.  
  365.     FPuts( Files->Std, "\n\tif( GList ) {\n"
  366.                "\t\ttc = 0;\n"
  367.                "\t\twhile( WTags[ tc ].ti_Tag != WA_Gadgets ) tc++;\n"
  368.                "\t\tWTags[ tc ].ti_Data = (ULONG)GList;\n"
  369.                "\t}\n\n" );
  370.  
  371.     if( IE->SrcFlags & FONTSENSITIVE )
  372.     FPuts( Files->Std, "\tww = ScaleX( WTags[ WT_WIDTH  ].ti_Data ) + XOffset + Scr->WBorRight;\n"
  373.                "\twh = ScaleY( WTags[ WT_HEIGHT ].ti_Data ) + YOffset + Scr->WBorBottom;\n"
  374.                "\n"
  375.                "\tif(( WTags[ WT_LEFT ].ti_Data + ww ) > Scr->Width  )\n"
  376.                "\t\tWTags[ WT_LEFT ].ti_Data = Scr->Width  - ww;\n"
  377.                "\tif(( WTags[ WT_TOP  ].ti_Data + wh ) > Scr->Height )\n"
  378.                "\t\tWTags[ WT_TOP  ].ti_Data = Scr->Height - wh;\n"
  379.                "\n"
  380.                "\toldww = WTags[ WT_WIDTH  ].ti_Data;\n"
  381.                "\toldwh = WTags[ WT_HEIGHT ].ti_Data;\n"
  382.                "\tWTags[ WT_WIDTH  ].ti_Data = ww;\n"
  383.                "\tWTags[ WT_HEIGHT ].ti_Data = wh;\n\n" );
  384.  
  385.     FPuts( Files->Std, "\tWTags[8].ti_Data = (ULONG)Scr;\n"
  386.                "\n\t*Wnd = OpenWindowTagList( NULL, &WTags[0] );\n\n" );
  387.  
  388.     if( IE->SrcFlags & FONTSENSITIVE )
  389.     FPuts( Files->Std, "\tWTags[ WT_WIDTH  ].ti_Data = oldww;\n"
  390.                "\tWTags[ WT_HEIGHT ].ti_Data = oldwh;\n\n" );
  391.  
  392.     FPuts( Files->Std, "\tif(!( *Wnd ))\n"
  393.                "\t\treturn( 4L );\n\n"
  394.                "\tGT_RefreshWindow( *Wnd, NULL );\n"
  395.                "\treturn( 0L );\n}\n"
  396.                "\n"
  397.                "void CloseWnd( struct Window **Wnd, struct Gadget **GList, struct Menu **Mn )\n"
  398.                "{\n"
  399.                "\tif( Mn ) {\n"
  400.                "\t\tif( *Wnd )\n"
  401.                "\t\t\tClearMenuStrip( *Wnd );\n\n"
  402.                "\t\tFreeMenus( *Mn );\n"
  403.                "\t\t*Mn = NULL;\n"
  404.                "\t}\n"
  405.                "\tif( *Wnd ) {\n"
  406.                "\t\tCloseWindow( *Wnd );\n"
  407.                "\t\t*Wnd = NULL;\n"
  408.                "\t}\n"
  409.                "\tif( GList ) {\n"
  410.                "\t\tFreeGadgets( *GList );\n"
  411.                "\t\t*GList = NULL;\n"
  412.                "\t}\n"
  413.                "}\n"
  414.                "\n"
  415.                "struct Gadget *MakeGadgets( struct Gadget **GList, struct Gadget *Gads[],\n"
  416.                "\tstruct NewGadget NGad[], UWORD GTypes[], ULONG GTags[], UWORD CNT )\n"
  417.                "{\n"
  418.                "\tstruct Gadget\t\t*g;\n"
  419.                "\tUWORD\t\t\tlc, tc;\n"
  420.                "\tstruct NewGadget\tng;\n\n"
  421.                "\tif(!( g = CreateContext( GList )))\n"
  422.                "\t\treturn( (struct Gadget *)-1 );\n\n"
  423.                "\tfor( lc = 0, tc = 0; lc < CNT; lc++ ) {\n\n"
  424.                "\t\tCopyMem(( char * )&NGad[ lc ], ( char * )&ng, ( long )sizeof( struct NewGadget ));\n"
  425.                "\t\tng.ng_VisualInfo = VisualInfo;\n" );
  426.  
  427.     if( IE->SrcFlags & FONTSENSITIVE )
  428.     FPuts( Files->Std, "\t\tng.ng_TextAttr = Font;\n"
  429.                "\t\tng.ng_LeftEdge = XOffset + ScaleX( ng.ng_LeftEdge );\n"
  430.                "\t\tng.ng_TopEdge  = YOffset + ScaleY( ng.ng_TopEdge  );\n"
  431.                "\t\tng.ng_Width    = ScaleX( ng.ng_Width  );\n"
  432.                "\t\tng.ng_Height   = ScaleY( ng.ng_Height );\n" );
  433.     else
  434.     FPuts( Files->Std, "\t\tng.ng_TopEdge  += YOffset;\n"
  435.                "\t\tng.ng_LeftEdge += XOffset;\n" );
  436.  
  437.     FPuts( Files->Std, "\t\tGads[ lc ] = g = CreateGadgetA((ULONG)GTypes[ lc ], g, &ng, (struct TagItem *)>ags[ tc ] );\n\n"
  438.                "\t\twhile( GTags[ tc ] )\n"
  439.                "\t\t\ttc += 2;\n"
  440.                "\t\ttc++;\n\n"
  441.                "\t\tif( !g )\n"
  442.                "\t\t\treturn( (struct Gadget *)-2 );\n"
  443.                "\t}\n\n"
  444.                "\treturn( g );\n"
  445.                "}\n" );
  446. }
  447. ///
  448.  
  449. /// WriteBackFillHook
  450. void WriteBackFillHook( struct GenFiles *Files, struct IE_Data *IE )
  451. {
  452.     struct WindowInfo  *wnd;
  453.  
  454.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ )
  455.     if( wnd->wi_Tags & W_BACKFILL ) {
  456.         TEXT    buffer[ 40 ];
  457.  
  458.         sprintf( buffer, Prefs.HookDef, "ULONG" );
  459.  
  460.         FPrintf( Files->Std, "\n%s WndBFHookFunc( A0( struct Hook *Hook ), A2( struct RastPort *Rast ), A1( struct BFHookMsg *Msg ))\n"
  461.                  "{\n"
  462.                  "\tstatic UWORD Pattern[] = { 0xAAAA, 0x5555 };\n"
  463.                  "\tstruct DrawInfo *dri;\n\n"
  464.                  "\tif( dri = GetScreenDrawInfo( Scr )) {\n"
  465.                  "\t\tSetABPenDrMd( Rast, dri->dri_Pens[ SHINEPEN ], dri->dri_Pens[ BACKPEN ], JAM2 );\n"
  466.                  "\t\tSetAfPt( Rast, &Pattern[0], 1 );\n"
  467.                  "\t\tBltPattern( Rast, NULL,\n"
  468.                  "\t\t            Msg->Bounds.MinX, Msg->Bounds.MinY,\n"
  469.                  "\t\t            Msg->Bounds.MaxX, Msg->Bounds.MaxY,\n"
  470.                  "\t\t            0 );\n"
  471.                  "\t\tSetAfPt( Rast, NULL, 0 );\n"
  472.                  "\t\tFreeScreenDrawInfo( Scr, dri );\n"
  473.                  "\t}\n"
  474.                  "\n\treturn( 0L );\n"
  475.                  "}\n",
  476.              buffer );
  477.  
  478.         break;
  479.     }
  480. }
  481. ///
  482.  
  483. /// WriteListHook
  484. void WriteListHook( struct GenFiles *Files, struct IE_Data *IE )
  485. {
  486.     if( CheckMultiSelect( IE )) {
  487.     TEXT    def[32];
  488.  
  489.     sprintf( def, Prefs.HookDef, "ULONG" );
  490.  
  491.     FPrintf( Files->XDef, "extern %s ListHookFunc( A0( struct Hook * ), A1( struct LVDrawMsg * ), A2( struct Node * ));\n"
  492.                   "\n#define ML_SELECTED  (1<<0)\n\n",
  493.          def );
  494.  
  495.     FPrintf( Files->Std, "\n"
  496.                  "%s ListHookFunc( A0( struct Hook *Hook ), A1( struct LVDrawMsg *Msg ), A2( struct Node *Node ))\n"
  497.                  "{\n"
  498.                  "\tULONG\t\t\tlen;\n"
  499.                  "\tstruct TextExtent\textent;\n"
  500.                  "\n"
  501.                  "\tif( Msg->lvdm_MethodID != LV_DRAW ) {\n"
  502.                  "\t\treturn( LVCB_UNKNOWN );\n"
  503.                  "\t}\n"
  504.                  "\n"
  505.                  "\tswitch( Msg->lvdm_State ) {\n"
  506.                  "\t\tcase LVR_NORMAL:\n"
  507.                  "\t\tcase LVR_NORMALDISABLED:\n"
  508.                  "\t\tcase LVR_SELECTED:\n"
  509.                  "\t\tcase LVR_SELECTEDDISABLED:\n"
  510.                  "\t\tlen = TextFit( Msg->lvdm_RastPort, Node->ln_Name,\n"
  511.                  "\t\t               strlen( Node->ln_Name ), &extent, NULL, 1,\n"
  512.                  "\t\t               Msg->lvdm_Bounds.MaxX - Msg->lvdm_Bounds.MinX - 3,\n"
  513.                  "\t\t               Msg->lvdm_Bounds.MaxY - Msg->lvdm_Bounds.MinY + 1 );\n"
  514.                  "\n"
  515.                  "\t\tMove( Msg->lvdm_RastPort, Msg->lvdm_Bounds.MinX + 2,\n"
  516.                  "\t\t      Msg->lvdm_Bounds.MinY + Msg->lvdm_RastPort->TxBaseline );\n"
  517.                  "\n"
  518.                  "\t\tif( Node->ln_Pri & ML_SELECTED ) {\n"
  519.                  "\t\t\tSetABPenDrMd( Msg->lvdm_RastPort, Msg->lvdm_DrawInfo->dri_Pens[ FILLTEXTPEN ],\n"
  520.                  "\t\t\t              Msg->lvdm_DrawInfo->dri_Pens[ FILLPEN ], JAM2 );\n"
  521.                  "\t\t} else {\n"
  522.                  "\t\t\tSetABPenDrMd( Msg->lvdm_RastPort, Msg->lvdm_DrawInfo->dri_Pens[ TEXTPEN ],\n"
  523.                  "\t\t\t              Msg->lvdm_DrawInfo->dri_Pens[ BACKGROUNDPEN ], JAM2 );\n"
  524.                  "\t\t}\n"
  525.                  "\n"
  526.                  "\t\tText( Msg->lvdm_RastPort, Node->ln_Name, len );\n"
  527.                  "\n"
  528.                  "\t\tSetAPen( Msg->lvdm_RastPort, Msg->lvdm_DrawInfo->dri_Pens[( Node->ln_Pri & ML_SELECTED ) ? FILLPEN : BACKGROUNDPEN ]);\n"
  529.                  "\t\tRectFill( Msg->lvdm_RastPort, Msg->lvdm_RastPort->cp_x, Msg->lvdm_Bounds.MinY,\n"
  530.                  "\t\t          Msg->lvdm_Bounds.MaxX, Msg->lvdm_Bounds.MaxY );\n"
  531.                  "\t\tbreak;\n"
  532.                  "\t}\n"
  533.                  "\n"
  534.                  "\treturn( LVCB_OK );\n"
  535.                  "}\n\n",
  536.          def );
  537.     }
  538. }
  539. ///
  540.  
  541. /// WriteGBanksHandling
  542. void WriteGBanksHandling( struct GenFiles *Files, struct IE_Data *IE )
  543. {
  544.     struct WindowInfo  *wnd;
  545.  
  546.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ )
  547.     if( wnd->wi_NumGBanks ) {
  548.  
  549.         FPuts( Files->XDef, "extern void AddGadgetBank( struct Window *, struct WindowBanks *, struct Gadget * );\n"
  550.                 "extern void RemGadgetBank( struct Window *, struct WindowBanks *, struct Gadget * );\n" );
  551.  
  552.         FPuts( Files->Std, "\nvoid AddGadgetBank( struct Window *Wnd, struct WindowBanks *WindowBanks, struct Gadget *Bank )\n"
  553.                    "{\n"
  554.                    "\tWindowBanks->Banks[ WindowBanks->Count++ ] = Bank;\n\n"
  555.                    "\tAddGList( Wnd, Bank, (UWORD)~0, -1, NULL );\n"
  556.                    "\tRefreshGadgets( Bank, Wnd, NULL );\n"
  557.                    "}\n\n"
  558.                    "void RemGadgetBank( struct Window *Wnd, struct WindowBanks *WindowBanks, struct Gadget *Bank )\n"
  559.                    "{\n"
  560.                    "\tUWORD   ReAttach = WindowBanks->Count - 1;\n\n"
  561.                    "\twhile( WindowBanks->Count > 0 ) {\n"
  562.                    "\t\tRemoveGList( Wnd, WindowBanks->Banks[ --WindowBanks->Count ], -1 );\n"
  563.                    "\t}\n\n"
  564.                    "\twhile( WindowBanks->Count < ReAttach ) {\n"
  565.                    "\t\tstruct Gadget *Bnk;\n\n"
  566.                    "\t\tif(( Bnk = WindowBanks->Banks[ WindowBanks->Count ]) != Bank ) {\n"
  567.                    "\t\t\tAddGList( Wnd, Bnk, (UWORD)~0, -1, NULL );\n"
  568.                    "\t\t\tWindowBanks->Banks[ WindowBanks->Count++ ] = Bnk;\n"
  569.                    "\t\t}\n"
  570.                    "\t}\n"
  571.                    "}\n\n" );
  572.         break;
  573.     }
  574. }
  575. ///
  576.  
  577. /// WriteRender
  578. void WriteRender( struct GenFiles *Files, struct IE_Data *IE )
  579. {
  580.     struct WindowInfo      *wnd;
  581.     struct BevelBoxNode    *box;
  582.     WORD                    x, y;
  583.  
  584.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  585.     if( wnd->wi_NeedRender ) {
  586.  
  587.         FPrintf( Files->XDef, "extern void %sRender( void );\n", wnd->wi_Label );
  588.  
  589.         FPrintf( Files->Std, "\nvoid %sRender( void )\n{\n", wnd->wi_Label );
  590.  
  591.         if( IE->SrcFlags & FONTSENSITIVE ) {
  592.  
  593.         if( wnd->wi_NumImages )
  594.             FPuts( Files->Std, "\tstruct Image\t\tim;\n"
  595.                        "\tstruct Image\t\t*imp;\n" );
  596.  
  597.         if( wnd->wi_NumTexts )
  598.             FPuts( Files->Std, "\tstruct IntuiText\tit;\n" );
  599.  
  600.         if(( wnd->wi_NumImages ) || ( wnd->wi_NumTexts ))
  601.             FPuts( Files->Std, "\tUWORD\t\t\tc;\n" );
  602.         }
  603.  
  604.         IE->win_info = wnd;
  605.         ( *IE->IEXSrcFun->RenderMinusZero )( Files );
  606.  
  607.         for( box = wnd->wi_Boxes.mlh_Head; box->bb_Next; box = box->bb_Next ) {
  608.         x = box->bb_Left - IE->ScreenData->XOffset;
  609.         y = box->bb_Top  - IE->ScreenData->YOffset;
  610.  
  611.         if( IE->SrcFlags & FONTSENSITIVE )
  612.             FPrintf( Files->Std, "\n\tDrawBevelBox( %sWnd->RPort, ScaleX( %ld ) + XOffset, ScaleY( %ld ) + YOffset, ScaleX( %ld ), ScaleY( %ld ),\n"
  613.                      "\t\tGT_VisualInfo, VisualInfo,",
  614.                  wnd->wi_Label, x, y, box->bb_Width, box->bb_Height );
  615.         else
  616.             FPrintf( Files->Std, "\n\tDrawBevelBox( %sWnd->RPort, %ld + XOffset, %ld + YOffset, %ld, %ld,\n"
  617.                      "\t\tGT_VisualInfo, VisualInfo,",
  618.                  wnd->wi_Label, x, y, box->bb_Width, box->bb_Height );
  619.  
  620.         if( box->bb_Recessed )
  621.             FPuts( Files->Std, " GTBB_Recessed, TRUE," );
  622.  
  623.         if( box->bb_FrameType != 1 )
  624.             VFPrintf( Files->Std, " GTBB_FrameType, %ld,", &box->bb_FrameType );
  625.  
  626.         FPuts( Files->Std, " TAG_DONE );\n" );
  627.         }
  628.  
  629.         if( wnd->wi_NumImages ) {
  630.         if( IE->SrcFlags & FONTSENSITIVE ) {
  631.             FPrintf( Files->Std, "\n\timp = &%s_0Image;\n"
  632.                      "\tfor( c = 0; c < %ld; c++ ) {\n"
  633.                      "\t\tCopyMem(( char * )imp, ( char * )&im, ( long )sizeof( struct Image ));\n"
  634.                      "\t\timp = imp->NextImage;\n"
  635.                      "\t\tim.NextImage = NULL;\n"
  636.                      "\t\tim.LeftEdge  = XOffset + ScaleX( im.LeftEdge );\n"
  637.                      "\t\tim.TopEdge   = YOffset + ScaleY( im.TopEdge  );\n"
  638.                      "\t\tDrawImage( %sWnd->RPort, &im, 0, 0 );\n"
  639.                      "\t}\n",
  640.                  wnd->wi_Label, wnd->wi_NumImages, wnd->wi_Label );
  641.         } else {
  642.             FPrintf( Files->Std, "\n\tDrawImage( %sWnd->RPort, &%s_0Image, XOffset, YOffset );\n",
  643.                  wnd->wi_Label, wnd->wi_Label );
  644.         }
  645.         }
  646.  
  647.         if( wnd->wi_NumTexts ) {
  648.         if( IE->SrcFlags & FONTSENSITIVE ) {
  649.             FPrintf( Files->Std, "\n\tfor( c = 0; c < %ld; c++ ) {\n"
  650.                      "\t\tCopyMem(( char * )&%sIText[ c ], ( char * )&it, ( long )sizeof( struct IntuiText ));\n"
  651.                      "\t\tit.ITextFont = Font;\n"
  652.                      "\t\tit.LeftEdge  = XOffset + ScaleX( it.LeftEdge ) - ( IntuiTextLength( &it ) >> 1 );\n"
  653.                      "\t\tit.TopEdge   = YOffset + ScaleY( it.TopEdge  ) - ( Font->ta_YSize >> 1 );\n"
  654.                      "\t\tPrintIText( %sWnd->RPort, &it, 0, 0 );\n"
  655.                      "\t}\n",
  656.                  wnd->wi_NumTexts, wnd->wi_Label, wnd->wi_Label );
  657.         } else {
  658.             FPrintf( Files->Std, "\n\tPrintIText( %sWnd->RPort, %sIText, XOffset, YOffset );\n",
  659.                  wnd->wi_Label, wnd->wi_Label );
  660.         }
  661.         }
  662.  
  663.         ( *IE->IEXSrcFun->RenderPlusZero )( Files );
  664.  
  665.         FPuts( Files->Std, "}\n" );
  666.  
  667.     }
  668.     }
  669. }
  670. ///
  671.  
  672.